<template>
  <div>
    <van-picker
      show-toolbar
      :columns="columns"
      @cancel="$emit('colse')"
      @confirm = "onConfirm"
      :default-index="defaultIndex"
      @change="changindex"
     
    />
  </div>
</template>
<script>
import { upUserDate } from "../../api/user"
export default {
    props:{
        value:{
            type:Number,
            required:true
        }
    },
    data(){
        return{
             columns: ['男','女'],
             defaultIndex:this.value
        }
    },
    methods:{
        changindex(a,b,c){
            // console.log(c)
            this.defaultIndex = c
            console.log(this.defaultIndex)

        },
        async onConfirm(){
             this.$toast.loading({
                message:'保存中',
                forbidClick:true
            })
            try{
                 await upUserDate({
                    gender:this.defaultIndex

                })
                // console.log(data)
                this.$toast.success('成功');
                this.$emit('input',this.defaultIndex)
                this.$emit('colse')
                console.log(this.value)

            }catch (err){
                if (err && err.response && err.response.status == 409){
                    this.$toast.fail('昵称已存在')

                }

            }
            
        }
        
        
    }
};
</script>
<style scoped>
</style>